#pragma once

#include "IGraphicModule.h"
#include "CTexture.h"

//namespace ArkGraphic
// {

struct STATIC_RS : public ARK_RENDERSTATE
{
	LPDIRTEX		m_Texture_S0;
	LPDIRTEX		m_Texture_S1;
	LPDIRTEX		m_Texture_S2;
	LPDIRTEX		m_Texture_S3;

	STATIC_RS();

	void SetRenderStyle( IGraphic* pGraphic, const STATIC_RS& RenderStyle );
	void ResetRenderStyle( IGraphic* pGraphic );
};


class CRenderStyle : public IRenderStyle, public CResUnit
{
	UINT					m_Ref;

	float					m_TimeRang;
	bool					m_bSyn;

	map<float,CColor4>		m_Ambient;
	map<float,CColor4>		m_Diffuse;
	map<float,CColor4>		m_Specular;
	map<float,CColor4>		m_Emissive;
	map<float,float>		m_Specularpower;
	map<float,DWORD>		m_Alpharef;
	map<float,DWORD>		m_Texturefactor;

	map<float,DWORD>		m_AlphaBlendEnable;
	map<float,DWORD>		m_SrcBlend;
	map<float,DWORD>		m_DestBlend;

	map<float,DWORD>		m_AlphaTestEnable;
	map<float,DWORD>		m_AlphaTestFun;

	map<float,DWORD>		m_LightEnable;
	map<float,DWORD>		m_SpecularEnable;

	map<float,DWORD>		m_ZTestEnable;
	map<float,DWORD>		m_ZTestFun;
	map<float,DWORD>		m_ZWR;

	map<float,DWORD>		m_Cull;
	map<float,DWORD>		m_FillMode;

	map<float,DWORD>		m_Texture_S0;
	map<float,DWORD>		m_Texture_S1;
	map<float,DWORD>		m_Texture_S2;
	map<float,DWORD>		m_Texture_S3;
	map<float,DWORD>		m_Sample_S0;
	map<float,DWORD>		m_Sample_S1;
	map<float,DWORD>		m_Sample_S2;
	map<float,DWORD>		m_Sample_S3;
	map<float,DWORD>		m_TexOP_S0;
	map<float,DWORD>		m_TexOP_S1;
	map<float,DWORD>		m_TexOP_S2;
	map<float,DWORD>		m_TexOP_S3;
	map<float,DWORD>		m_TexArg1_S0;
	map<float,DWORD>		m_TexArg1_S1;
	map<float,DWORD>		m_TexArg1_S2;
	map<float,DWORD>		m_TexArg1_S3;
	map<float,DWORD>		m_TexArg2_S0;
	map<float,DWORD>		m_TexArg2_S1;
	map<float,DWORD>		m_TexArg2_S2;
	map<float,DWORD>		m_TexArg2_S3;
	map<float,DWORD>		m_AlpOP_S0;
	map<float,DWORD>		m_AlpOP_S1;
	map<float,DWORD>		m_AlpOP_S2;
	map<float,DWORD>		m_AlpOP_S3;
	map<float,DWORD>		m_AlpArg1_S0;
	map<float,DWORD>		m_AlpArg1_S1;
	map<float,DWORD>		m_AlpArg1_S2;
	map<float,DWORD>		m_AlpArg1_S3;
	map<float,DWORD>		m_AlpArg2_S0;
	map<float,DWORD>		m_AlpArg2_S1;
	map<float,DWORD>		m_AlpArg2_S2;
	map<float,DWORD>		m_AlpArg2_S3;
	map<float,DWORD>		m_UVSrc_S0;
	map<float,DWORD>		m_UVSrc_S1;
	map<float,DWORD>		m_UVSrc_S2;
	map<float,DWORD>		m_UVSrc_S3;
	map<float,DWORD>		m_UAddr_S0;
	map<float,DWORD>		m_UAddr_S1;
	map<float,DWORD>		m_UAddr_S2;
	map<float,DWORD>		m_UAddr_S3;
	map<float,DWORD>		m_VAddr_S0;
	map<float,DWORD>		m_VAddr_S1;
	map<float,DWORD>		m_VAddr_S2;
	map<float,DWORD>		m_VAddr_S3;
	map<float,DWORD>		m_MipMapSample_S0;
	map<float,DWORD>		m_MipMapSample_S1;
	map<float,DWORD>		m_MipMapSample_S2;
	map<float,DWORD>		m_MipMapSample_S3;
	map<float,DWORD>		m_MipMapBias_S0;
	map<float,DWORD>		m_MipMapBias_S1;
	map<float,DWORD>		m_MipMapBias_S2;
	map<float,DWORD>		m_MipMapBias_S3;

	IGraphic*				m_pGraphic;


	friend class CGraphic;
	CRenderStyle( CResourceContainer* pContainer, CResourceRecycle* pRecycle, const string& szName );
	~CRenderStyle(void);

public:

	int				BinLoad( IGraphic* pGraphic );
	void			GetCurRenderStyle( STATIC_RS& RenderStyle, const ITexture** pTextureList, int nListNum, float Time, void* pUser ) const;

	bool			IsAlphaBlend( float Time )	{ return GetMapState( m_AlphaBlendEnable, Time/m_TimeRang ) != 0; }
	LPCTSTR			GetName()					{ return m_szName.c_str(); }
	UINT			AddRef()					{ return ++m_Ref; };
	virtual void	Release()					{ if( --m_Ref == 0 )FreeRes(); };
};

/*};*/